<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>鸿蒙微信浏览器全屏Demo</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background-color: #f0f0f0;
            text-align: center;
            padding: 20px;
        }
        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            border-radius: 12px;
            padding: 40px 20px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 30px;
            font-size: 24px;
        }
        p {
            color: #666;
            margin-bottom: 40px;
            line-height: 1.6;
        }
        .btn {
            display: inline-block;
            padding: 15px 30px;
            font-size: 18px;
            font-weight: bold;
            color: white;
            background-color: #07c160;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .btn:hover {
            background-color: #06ad56;
        }
        .btn:active {
            transform: scale(0.98);
        }
        .status {
            margin-top: 30px;
            padding: 15px;
            background-color: #f5f5f5;
            border-radius: 8px;
            color: #333;
            font-size: 16px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>鸿蒙微信浏览器全屏Demo</h1>
        <p>点击下方按钮测试鸿蒙端微信浏览器的全屏功能</p>
        <button class="btn" id="fullscreenBtn">进入全屏</button>
        <div class="status" id="status"></div>
    </div>

    <script>
        // 检查浏览器是否支持全屏API
        function checkFullscreenSupport() {
            const element = document.documentElement;
            return !!(element.requestFullscreen ||
                     element.webkitRequestFullscreen ||
                     element.mozRequestFullScreen ||
                     element.msRequestFullscreen);
        }

        // 进入全屏
        function requestFullscreen() {
            const element = document.body;
            let promise;
            
            if (element.requestFullscreen) {
                promise = element.requestFullscreen();
            } else if (element.webkitRequestFullscreen) {
                promise = element.webkitRequestFullscreen();
            } else if (element.mozRequestFullScreen) {
                promise = element.mozRequestFullScreen();
            } else if (element.msRequestFullscreen) {
                promise = element.msRequestFullscreen();
            }
            
            return promise;
        }

        // 退出全屏
        function exitFullscreen() {
            let promise;
            
            if (document.exitFullscreen) {
                promise = document.exitFullscreen();
            } else if (document.webkitExitFullscreen) {
                promise = document.webkitExitFullscreen();
            } else if (document.mozCancelFullScreen) {
                promise = document.mozCancelFullScreen();
            } else if (document.msExitFullscreen) {
                promise = document.msExitFullscreen();
            }
            
            return promise;
        }

        // 检查是否处于全屏状态
        function isFullscreen() {
            return !!(document.fullscreenElement ||
                      document.webkitFullscreenElement ||
                      document.mozFullScreenElement ||
                      document.msFullscreenElement);
        }

        // 更新状态
        function updateStatus(message) {
            document.getElementById('status').textContent = message;
        }

        // 事件监听
        document.getElementById('fullscreenBtn').addEventListener('click', async () => {
            const btn = document.getElementById('fullscreenBtn');
            
            try {
                if (isFullscreen()) {
                    await exitFullscreen();
                    btn.textContent = '进入全屏';
                    updateStatus('已退出全屏');
                } else {
                    await requestFullscreen();
                    btn.textContent = '退出全屏';
                    updateStatus('已进入全屏');
                }
            } catch (error) {
                console.error('全屏操作失败:', error);
                updateStatus(`全屏操作失败: ${error.message}`);
            }
        });

        // 监听全屏状态变化
        document.addEventListener('fullscreenchange', handleFullscreenChange);
        document.addEventListener('webkitfullscreenchange', handleFullscreenChange);
        document.addEventListener('mozfullscreenchange', handleFullscreenChange);
        document.addEventListener('MSFullscreenChange', handleFullscreenChange);

        function handleFullscreenChange() {
            const btn = document.getElementById('fullscreenBtn');
            if (isFullscreen()) {
                btn.textContent = '退出全屏';
                updateStatus('已进入全屏');
            } else {
                btn.textContent = '进入全屏';
                updateStatus('已退出全屏');
            }
        }

        // 初始化
        window.addEventListener('load', () => {
            if (checkFullscreenSupport()) {
                updateStatus('浏览器支持全屏API');
            } else {
                updateStatus('浏览器不支持全屏API');
                document.getElementById('fullscreenBtn').disabled = true;
            }
        });
    </script>
</body>
</html>